package com.local.videoplayer.utils;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.local.videoplayer.R;
import com.local.videoplayer.app.MyApplication;

/**
 * Toast工具类
 *
 * @author ccx
 */
public class ToastUtil {

    private static Toast mToast;

    /**
     * Toast
     *
     * @param msg
     *         消息
     */
    public static void toast(String msg) {
        if (mToast != null) {
            mToast.cancel();
        }
        mToast = new Toast(MyApplication.getInstance().getApplicationContext());
        View view =
                LayoutInflater.from(MyApplication.getInstance()).inflate(R.layout.view_toast, null);
        TextView tv_toast = (TextView) view.findViewById(R.id.tv_toast);
        tv_toast.setText(msg.trim());
        mToast.setView(view);
        mToast.show();
    }

    /**
     * Toast
     *
     * @param resId
     *         消息ID
     */
    public static void toast(int resId) {
        if (mToast != null) {
            mToast.cancel();
        }
        mToast = new Toast(MyApplication.getInstance());
        View view =
                LayoutInflater.from(MyApplication.getInstance()).inflate(R.layout.view_toast, null);
        TextView tv_toast = (TextView) view.findViewById(R.id.tv_toast);
        tv_toast.setText(resId);
        mToast.setView(view);
        mToast.show();
    }

    /**
     * Toast
     *
     * @param msg
     *         消息
     */
    public static void toastCenter(String msg) {
        if (mToast != null) {
            mToast.cancel();
        }
        mToast = new Toast(MyApplication.getInstance());
        View view =
                LayoutInflater.from(MyApplication.getInstance()).inflate(R.layout.view_toast, null);
        TextView tv_toast = (TextView) view.findViewById(R.id.tv_toast);
        tv_toast.setText(msg.trim());
        mToast.setView(view);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.show();
    }

    ///**
    // * @param context
    // * @param response
    // * @param <D>
    // */
    //public static <D extends BaseResultInfo> void toastError(Context context,
    //        D response)
    //{
    //	if (response == null)
    //	{
    //		if (!Tools.isConnectNet(context))
    //		{
    //			ToastUtil.toast(context.getString(R.string.no_net_toast));
    //		}
    //		else
    //		{
    //			ToastUtil.toast(context.getString(R.string.newhouse_net_busy));
    //		}
    //	}
    //	else if (!ResponseTools.isResponseSuc(response))
    //	{
    //		ToastUtil.toast(context.getString(R.string.newhouse_net_busy));
    //	}
    //}

    ///**
    //* 通过错误码，给用户进行消息提示
    //*
    //* @param result
    //*/
    //public static void toastError(BaseResultInfo result)
    //{
    //
    //   if (result != null)
    //   {
    //       toastError(result.errno);
    //   }
    //
    //}
    //public static void toastError(int errorNo)
    //{
    //   int errorRes = R.string.something_wrong;
    //   switch (errorNo)
    //   {
    //       case 10001:
    //           errorRes = R.string.error_system;
    //           break;
    //       case 10002:
    //           errorRes = R.string.error_service;
    //           break;
    //       case 10020:
    //           errorRes = R.string.error_api;
    //           break;
    //       case 10030:
    //           errorRes = R.string.error_sms;
    //           break;
    //       case 10031:
    //           errorRes = R.string.error_voice;
    //           break;
    //       case 20001:
    //           errorRes = R.string.error_access_token;
    //           break;
    //       case 20004:
    //           errorRes = R.string.error_id_not_exists;
    //           break;
    //       case 20005:
    //           errorRes = R.string.error_request_times;
    //           break;
    //       case 20010:
    //           errorRes = R.string.error_password;
    //           break;
    //       case 20011:
    //           errorRes = R.string.error_username;
    //           break;
    //       case 20012:
    //           errorRes = R.string.error_auth_code;
    //           break;
    //       case 20013:
    //           errorRes = R.string.error_username_repeat;
    //           break;
    //       case 20014:
    //           errorRes = R.string.error_password_short;
    //           break;
    //       case 20015:
    //           errorRes = R.string.error_phone_number;
    //           break;
    //       case 20019:
    //           errorRes = R.string.new_password_no_change;
    //           break;
    //       case 20020:
    //           errorRes = R.string.error_has_bind_agent;
    //           break;
    //       case 20022:
    //           errorRes = R.string.error_picture_auth_code;
    //           break;
    //       case ConstantUtil.IDENTIFY_ERRO_CODE:
    //           errorRes = R.string.error_input_identify;
    //           break;
    //       case ConstantUtil.ERRORNO_UNBIND_MOBILE:
    //           errorRes = R.string.error_access_token;
    //           break;
    //   }
    //	ToastUtil.toast(errorRes);
    //}
}
